<template>
    <div class="container-content">
        <el-form
            ref="elForm"
            :model="formData"
            :rules="rules"
            size="medium"
            label-width="100px"
        >
            <!-- <el-form-item label-width="200px" label="编码" prop="rateCode">
                <el-input
                    v-model="formData.rateCode"
                    placeholder="请输入编码"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item> -->
            <el-form-item label-width="200px" label="描述" prop="companyDesc">
                <el-input
                    v-model="formData.companyDesc"
                    placeholder="请输入描述"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="数据状态"
                prop="dataStatus"
            >
                <el-select
                    v-model="formData.dataStatus"
                    placeholder="请选择数据状态"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in dataStatusOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="是否禁用"
                prop="isDisabled"
            >
                <el-select
                    v-model="formData.isDisabled"
                    placeholder="请选择是否禁用"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in isDisabledOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label-width="200px" label="名称" prop="title">
                <el-input
                    v-model="formData.title"
                    placeholder="请输入名称"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="生效日期"
                prop="effectiveTime"
            >
                <el-date-picker
                    v-model="formData.effectiveTime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    :style="{ width: '100%' }"
                    placeholder="请选择生效日期"
                    clearable
                ></el-date-picker>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="失效日期"
                prop="invalidTime"
            >
                <el-date-picker
                    v-model="formData.invalidTime"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    :style="{ width: '100%' }"
                    placeholder="请选择失效日期"
                    clearable
                ></el-date-picker>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="是否增值税"
                prop="isAddTax"
            >
                <el-select
                    v-model="formData.isAddTax"
                    placeholder="请选择是否增值税"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in isAddTaxOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
           
            <el-form-item
                label-width="200px"
                label="是否开增值税发票"
                prop="isTaxInvoice"
            >
                <el-select
                    v-model="formData.isTaxInvoice"
                    placeholder="请选择是否开增值税发票"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in isTaxInvoiceOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label-width="200px" label="税率" prop="rate">
                <el-input
                    v-model="formData.rate"
                    placeholder="请输入税率"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item>
            <el-form-item label-width="200px" label="税收制度" prop="taxSystem">
                <el-select
                    v-model="formData.taxSystem"
                    placeholder="请选择税收制度"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in taxSystemOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label-width="200px" label="	税种" prop="taxCategory">
                <el-select
                    v-model="formData.taxCategory"
                    placeholder="请选择	税种"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in taxCategoryOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
             <el-form-item
                label-width="200px"
                 label="买方代扣代缴"
            >
                <el-select
                    v-model="formData.isBuyReplace"
                    placeholder="请选择买方代扣代缴"
                    clearable
                    :style="{ width: '100%' }"
                    :disabled="formData.isSellReplace==1? true:false"
                >
                    <el-option
                        v-for="(item, index) in isBuyReplaceOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="卖方代扣代缴"
            >
                <el-select
                    v-model="formData.isSellReplace"
                    placeholder="请选择卖方代扣代缴"
                    clearable
                    :style="{ width: '100%' }"
                    :disabled="formData.isBuyReplace==1? true:false"
                >
                    <el-option
                        v-for="(item, index) in isSellReplaceOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { add } from "@/api/base/data";
import { updataKingBaseTaxRateList,editKingBaseTaxRateList } from "@/api/bim/outher";
export default {
    components: {},
     props: ["id"],
    data() {
        return {
            flag:false,
            formData: {
                rateCode: undefined,
                companyDesc: undefined,
                dataStatus: undefined,
                isDisabled: undefined,
                title: undefined,
                effectiveTime: null,
                invalidTime: null,
                isAddTax: undefined,
                isBuyReplace: undefined,
                isSellReplace: undefined,
                isTaxInvoice: undefined,
                rate: undefined,
                taxSystem: undefined,
                taxCategory: undefined,
            },
            rules: {
                rateCode: [
                    {
                        required: true,
                        message: "请输入编码",
                        trigger: "blur",
                    },
                ],
                companyDesc: [
                    {
                        required: true,
                        message: "请输入描述",
                        trigger: "blur",
                    },
                ],
                dataStatus: [
                    {
                        required: true,
                        message: "请选择数据状态",
                        trigger: "change",
                    },
                ],
                isDisabled: [
                    {
                        required: true,
                        message: "请选择是否禁用",
                        trigger: "change",
                    },
                ],
                title: [
                    {
                        required: true,
                        message: "请输入名称",
                        trigger: "blur",
                    },
                ],
                effectiveTime: [
                    {
                        required: true,
                        message: "请选择生效日期",
                        trigger: "change",
                    },
                ],
                invalidTime: [
                    {
                        required: true,
                        message: "请选择失效日期",
                        trigger: "change",
                    },
                ],
                isAddTax: [
                    {
                        required: true,
                        message: "请选择是否增值税",
                        trigger: "change",
                    },
                ],
                isBuyReplace: [
                    {
                        required: true,
                        message: "请选择买方代扣代缴",
                        trigger: "change",
                    },
                ],
                isSellReplace: [
                    {
                        required: true,
                        message: "请选择卖方代扣代缴",
                        trigger: "change",
                    },
                ],
                isTaxInvoice: [
                    {
                        required: true,
                        message: "请选择是否开增值税发票",
                        trigger: "change",
                    },
                ],
                rate: [
                    {
                        required: true,
                        message: "请输入税率",
                        trigger: "blur",
                    },
                ],
                taxSystem: [
                    {
                        required: true,
                        message: "请选择税收制度",
                        trigger: "change",
                    },
                ],
                taxCategory: [
                    {
                        required: true,
                        message: "请选择	税种",
                        trigger: "change",
                    },
                ],
            },
            dataStatusOptions: [
                {
                    label: "创建",
                    value: 1,
                },
                {
                    label: "审核中",
                    value: 2,
                },
                {
                    label: "已审核",
                    value: 3,
                },
            ],
            isDisabledOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
            isAddTaxOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
            isBuyReplaceOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
            isSellReplaceOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
            isTaxInvoiceOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
            taxSystemOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
            taxCategoryOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
        };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
        if (this.id!='') {
            updataKingBaseTaxRateList(this.id).then((res)=>{
                this.formData=res.data
                thia.flag=true
            })
        }
    },
    methods: {
        submitForm(cb) {
            if (this.flag) {
                this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                editKingBaseTaxRateList(this.formData, "KingBaseTaxRate").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("修改成功");
                        this.flag=false
                    }
                });
            });
            }else{
this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                add(this.formData, "KingBaseTaxRate").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("新增成功");
                    }
                });
            });
            }
            
        },
        resetForm() {
            this.$refs["elForm"].resetFields();
        },
    },
};
</script>
<style></style>
